import { DBListItem, DBListGetResultDB } from './model';
import { defHttp } from '/@/utils/http/axios';

enum Api {
  InfoSOURCE = '/admin/dbsource',
  ADDSOURCE = '/admin/dbsource/add',
  DelSOURCE = '/admin/dbsource/del',
  UpdateSOURCE = '/admin/dbsource/update',
  DB_PAGE = '/admin/dbsource/page',
  DB_LIST = '/admin/dbsource/getOptions',
  DB_SYNCDATABASE = '/admin/tabledefine/syncDataBase',
}

export const getDBListApi = (params?: { type: string }) =>
  defHttp.get<DBListItem[]>({ url: Api.DB_LIST, params });

export const getDBPageApi = (params?: DBListItem) =>
  defHttp.get<DBListGetResultDB>({ url: Api.DB_PAGE, params });

export const saveDBApi = (params?: DBListItem) => defHttp.post<any>({ url: Api.ADDSOURCE, params });

export const updateDBApi = (params?: DBListItem) =>
  defHttp.post<any>({ url: Api.UpdateSOURCE, params });

export const getDBInfoApi = (id: string) =>
  defHttp.get<DBListItem>({ url: Api.InfoSOURCE + '/' + id });

export const delDBApi = (id: string) => defHttp.post<any>({ url: Api.DelSOURCE + '/' + id });

export const syncDataBase = (dataSource: string) =>
  defHttp.post<any>({ url: Api.DB_SYNCDATABASE + '/' + dataSource });
